package com.example.spring_aop.aspect;

import lombok.extern.slf4j.Slf4j;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.After;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Before;
import org.springframework.stereotype.Component;

/**
 * @className: MyAspectDemo
 * @author: 芃
 * @description:
 * @date: 2024/12/30 14:28
 */
@Aspect
@Component
@Slf4j
public class MyAspectDemo {

    @Before("@annotation(com.example.spring_aop.aspect.MyAspect)")
    public void before(){
        log.info("MyAspectDemo.Before");
    }

    @After("@annotation(com.example.spring_aop.aspect.MyAspect)")
    public void after(){
        log.info("MyAspectDemo.After");
    }

    @Around("@annotation(com.example.spring_aop.aspect.MyAspect)")
    public Object around(ProceedingJoinPoint joinPoint) throws Throwable {
        long start = System.currentTimeMillis();
        Object result = joinPoint.proceed();
        long end = System.currentTimeMillis();
        log.info("MyAspectDemo.Around, time: " + (end - start) + "ms");
        return result;
    }
}
